﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PureMVC.Interfaces;
using PureMVC.Patterns.Observer;
using System;

namespace PureMVC.Patterns.Command
{
    public class MacroCommand : Notifier, ICommand
    {
        public MacroCommand()
        {
            childCommands = new Queue<Func<ICommand>>();
            InitializeMacroCommand();
        }

        protected virtual void InitializeMacroCommand()
        {

        }

        protected virtual void AddChildCommand(Func<ICommand> _commandFactory)
        {
            childCommands.Enqueue(_commandFactory);
        }

        public void Execute(INotification Notification)
        {
            while (childCommands.Count > 0)
            {
                ICommand command = childCommands.Dequeue()();
                command.InitializeNotifier(MultitonKey);
                command.Execute(Notification);
            }
        }

        public Queue<Func<ICommand>> childCommands;
    }
}